package handler

import (
	"github.com/gin-gonic/gin"
	"net/http"
	"path"
)

func UploadFile(c *gin.Context) {
	file, err := c.FormFile("file")
	if err != nil {
		return
	}
	ext := path.Ext(file.Filename)

	dst := "D:\\phpstudy_pro\\WWW\\" + file.Filename
	if ext != ".png" && ext != ".jpg" && ext != ".mp4" {
		c.JSON(http.StatusOK, gin.H{
			"code": 10000,
			"msg":  "上传文件格式失败",
			"data": nil,
		})
		return
	}

	if file.Size > 1024*1024*50 {
		c.JSON(http.StatusOK, gin.H{
			"code": 10000,
			"msg":  "上传文件不能超过50MB",
			"data": nil,
		})
		return
	}
	c.JSON(http.StatusOK, gin.H{
		"code": http.StatusOK,
		"msg":  "上传文件成功",
		"data": dst,
		//"D:\phpstudy_pro\WWW\1110bc5e4c3f7df0428c9d2539c76f84.jpg"
	})

}
